package com.zztl.infiniteBand.adapter

import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.zztl.infiniteBand.R
import com.zztl.infiniteBand.model.ServiceNoticeDatamapBean
import com.zztl.infiniteBand.ui.view.CommonItemView
import com.zztl.infiniteBand.util.DataFormatUtil
import com.zztl.infiniteBand.util.UiUtils

/**
 * @desc
 * @auth ${user}
 * @time 2018/6/13  20:02
 */
class ServiceMessageAdapter(layoutResId: Int, data: List<ServiceNoticeDatamapBean>?) : BaseQuickAdapter<ServiceNoticeDatamapBean, BaseViewHolder>(layoutResId, data) {

    override fun convert(helper: BaseViewHolder, item: ServiceNoticeDatamapBean) {
        if (item.dataMap!!.transactionMoney> 0) {
            helper.setText(R.id.tv_money, "+" + DataFormatUtil.converTxtPoint4(item.dataMap!!.transactionMoney))
        } else {
            helper.setText(R.id.tv_money, DataFormatUtil.converTxtPoint4(item.dataMap!!.transactionMoney))
        }
        helper.setText(R.id.tv_unit, item.dataMap!!.currencyName)
        /*if (item.dataMap!!.status != null) {
            helper.setText(R.id.tv_state, if (item.dataMap!!.status == "0") UiUtils.getString(R.string.成功) else UiUtils.getString(R.string.确认中))
            helper.setTextColor(R.id.tv_state, if (item.dataMap!!.status == "0") UiUtils.getColor(R.color.color_2ECC71) else UiUtils.getColor(R.color.color_2628F4))
            helper.setBackgroundRes(R.id.tv_state, if (item.dataMap!!.status == "0") R.drawable.button_ebf9f0_bg else R.drawable.button_ebf9f0_bg)
        }*/

        if (item?.dataMap?.status.equals("0") ) {
            helper.setText(R.id.tv_state, UiUtils.getString(R.string.成功))
            helper.setTextColor(R.id.tv_state, UiUtils.getColor(R.color.color_2ECC71))
            helper.setBackgroundRes(R.id.tv_state, R.drawable.button_ebf9f0_bg)
        } else if (item?.dataMap?.status.equals("2")) {
            helper.setText(R.id.tv_state, UiUtils.getString(R.string.确认中))
            helper.setTextColor(R.id.tv_state, UiUtils.getColor(R.color.color_2628F4))
            helper.setBackgroundRes(R.id.tv_state, R.drawable.button_e9e9fd_bg)
        } else if(item?.dataMap?.status.equals("1")){
            helper.setText(R.id.tv_state, UiUtils.getString(R.string.失败))
            helper.setTextColor(R.id.tv_state, UiUtils.getColor(R.color.color_FE1D00))
            helper.setBackgroundRes(R.id.tv_state, R.drawable.button_ebf9f0_bg)
        }

        //            CommonItemView itemExplain = helper.getView(R.id.item_explain);
        helper.setText(R.id.tv_explain, item.dataMap!!.transactionTheme)
        val itemAddress = helper.getView<CommonItemView>(R.id.item_address)
        if (null == item.dataMap!!.targetAddress) {
            itemAddress.visibility = View.GONE
        } else {
            itemAddress.visibility = View.VISIBLE
            itemAddress.rightTextStr = item.dataMap!!.targetAddress
        }
        val itemTime = helper.getView<CommonItemView>(R.id.item_time)
        itemTime.rightTextStr = item.dataMap!!.confirmTimeStr

    }

}



